#ifndef __STRING_UTIL_HH__
#define __STRING_UTIL_HH__

#include <string>
#include <vector>
using namespace std;

void string_strip(string* s);
void string_strip(vector<string>* vs);
void string_split(const char* s_, vector<string>* out, const string& del);
pair<string, string> string_split_to_pair(const char* s_, const string& del);
void string_replace(string* source, const string& find, const string& replace);

template <class V>
inline
void string_join(ostream* out, const vector<V>& in, const string& del)
{
  if (in.size() == 0) {
    return;
  }

  int i = 0;
  while (i < in.size() - 1) {
    *out << in[i++] << del;
  }
  *out << in[i];
}

string sfmt(const char* fmt, ...);

template <class T>
void SNPrintF(char* buf, size_t buf_len, const void* v_ptr);

template <>
inline void SNPrintF<int>(char* buf, size_t buf_len, const void* v_ptr)
{
  snprintf(buf, buf_len, "%d", *(const int*)v_ptr);
}

template <>
inline void SNPrintF<double>(char* buf, size_t buf_len, const void* v_ptr)
{
  snprintf(buf, buf_len, "%f", *(const double*)v_ptr);
}

#endif
